package charstream;

import java.io.*;
import java.util.Arrays;

public class Demo10 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("Day13\\a.txt"));
        //1.读取数据
        String line = br.readLine();
        System.out.println("读取数据:"+line);
        br.close();
        //2.按照空格切换，转换成String类型数组
        String[] s = line.split(" ");
        //3.把String数组转换成int类型
        int [] arr =new int[s.length];
        //遍历s数组，进行类型转换
        for (int i = 0; i < s.length; i++) {
            int num = Integer.parseInt(s[i]);
            arr[i] = num;
        }
        //4.排序
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
        //5.写出，排序之后回到本地
        BufferedWriter bw = new BufferedWriter(new FileWriter("Day13\\a.txt"));
        for (int i = 0; i < arr.length; i++) {
            bw.write(arr[i]+" ");
            bw.flush();
        }
        bw.close();
    }
}
